/**
 * 图片构造函数
 */
export default function ImageMonitor() {
  const images = []
  this.createImage = (src) => {
    let result = typeof images[src] !== 'undefined' ? images[src] : (images[src] = new Image(), images[src].src = src, images[src])
    return result
  }
  this.loadImage = (arr, callback) => {
    arr.forEach((v, i) => {
      images[v] = new Image()
      // 全部图片加载完毕才触发回调
      images[v].onload = () => {
        if (i === arr.length - 1 && typeof callback === 'function') callback()
      }
      images[v].src = v
    })
  }
}
